package sync.quartz;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import sync.ssc.SyncPK;
import sync.ssc.SyncSSC;

public class SSCJob implements Job{

	private static int sscCount = 1;

	private static Logger logger = LoggerFactory.getLogger(SSCJob.class.getName());

	public SSCJob(){}

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		syncData();
	}

	private static boolean syncData(){
		try {
			// 第一次去官网
			SyncSSC sync = new SyncSSC();
			sync.getDataFromGuanWang2();
			logger.debug("官网二同步成功");
			return true;
		} catch (Exception e1) {
			logger.debug("同步官网二", e1);
			try {
				// 第三次去网易
				SyncSSC sync = new SyncSSC();
				sync.getWangyiData();
				logger.debug("网易同步成功");
				return true;
			} catch (Exception e2) {
				e2.printStackTrace();
				logger.debug("网易同步", e2);
				System.out.println("同步ssc    "+sscCount);
				if(sscCount >= 5){
					logger.debug("同步失败，重新开始对本次数据抓取");
					sscCount = 1;
					return true;
				}
				try {
					Thread.sleep(10000);
					sscCount++;
					syncData();
				} catch (InterruptedException e3) {
					// TODO Auto-generated catch block
					//e3.printStackTrace();
				}
				return false;
			}
		}
	}
}

